{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "0baac6c4-0b87-4bef-b83a-d7cbd00bff63",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import openpyxl\n",
    "import datetime\n",
    "from colorsys import rgb_to_hls, hls_to_rgb\n",
    "from openpyxl.styles.colors import COLOR_INDEX\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "# 加载玩家的基础信息，方便后面直接调用函数\n",
    "player_list = pd.read_excel('Player Information.xlsx', index_col=0).to_dict('index') # index是player_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "b705267a-81e7-439b-9e09-c0e746ce0f6c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# L1\n",
    "import pandas as pd\n",
    "\n",
    "upgrade_xp = [400]  # 升级所需经验\n",
    "total_xp = [0]  # 累积经验\n",
    "for i in range(1, 100):\n",
    "    total_xp.append(total_xp[i-1] + upgrade_xp[i-1])\n",
    "    upgrade_xp.append(upgrade_xp[i-1]*1.125)\n",
    "\n",
    "global degree\n",
    "degree = pd.DataFrame({'degree': range(1, 101), 'total_xp': total_xp, 'upgrade_xp': upgrade_xp})\n",
    "\n",
    "# 输入当前经验值查询等级\n",
    "# current_xp = 9500\n",
    "# print('当前等级：', degree[degree['total_xp'] <= current_xp]['degree'].max())\n",
    "\n",
    "# 写入player_list\n",
    "for i in range(len(player_list)):\n",
    "    player_list[i].update({'Degree': degree[degree['total_xp'] <= current_xp]['degree'].max()})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "963bcc06-0b96-472c-a74f-fca4eb433eb7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "472b3dc8-ebb4-432e-88e0-49e1bf80cfab",
   "metadata": {},
   "outputs": [],
   "source": [
    "# L2\n",
    "location = pd.read_excel('L2.xlsx', sheet_name='location')   # 加载种族位置顺序表\n",
    "site = pd.read_excel('L2.xlsx', sheet_name='site')   # 任务顺序表\n",
    "\n",
    "\n",
    "def get_money(race, init_xp, gold_collected, current_location):\n",
    "    '''\n",
    "    :param race: 种族\n",
    "    :param init_xp: 初始xp\n",
    "    :param gold_collected: 初始金币\n",
    "    :param current_location: 当前位置\n",
    "    :return: 达到40级时的经验值、银币数量\n",
    "    '''\n",
    "    degree_xp = degree[degree['degree'] == 40]['total_xp'].values[0]  # 达到40级的累积经验\n",
    "    race_location_sort = location[race] # 根据种族查找位置顺序\n",
    "    quest_location = list(race_location_sort).index(current_location)\n",
    "    df = site[site['Location'].isin(race_location_sort[quest_location:])]\n",
    "    df['Location'] = pd.Categorical(df['Location'], categories=race_location_sort)\n",
    "    df = df.sort_values(['Location', 'Quest ID'])\n",
    "    df['gold_collected_cumsum'] = df['Gold Granted'].cumsum()\n",
    "    df['xp_cumsum'] = df['XP Granted'].cumsum()\n",
    "    total_xp = df[df['xp_cumsum'] > (degree_xp - init_xp)]['xp_cumsum'].min()  # 达到40级时获得的xp\n",
    "    gold_granted = df[df['xp_cumsum'] > (degree_xp - init_xp)]['gold_collected_cumsum'].min()  # 达到40级时获得的金币\n",
    "    current_location = df[df['xp_cumsum'] > (degree_xp - init_xp)]['Location'].iloc[0] # 40级时的位置\n",
    "    total_xp += init_xp\n",
    "    total_sliver = int(round((gold_collected + gold_granted) * 100, 0))\n",
    "    return total_xp, total_sliver\n",
    "\n",
    "\n",
    "for i in range(len(player_list)):\n",
    "    total_xp, total_sliver= get_money(player_list[i]['Race'], player_list[i]['Initial XP'], player_list[i]['Initial Gold'], player_list[i]['Initial Location'])\n",
    "    player_list[i].update({\n",
    "        'Degree': 40,\n",
    "        'Total XP': total_xp, # 总经验值\n",
    "        'Total Sliver': total_sliver, # 后续结果均以银币数量为主，故加入银币数字段\n",
    "    })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a53f59e-bf7d-44ab-bc15-5da682570a9d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "bee876ce-eee4-4f03-8453-b82a81c3d05a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入player_id：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 1\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入种族：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Orc\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入初始xp：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 6945\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入初始金币：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 27.42\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入当前位置：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Durotar\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "745.0000000000002\n"
     ]
    }
   ],
   "source": [
    "# L3\n",
    "\n",
    "resource = pd.read_excel('L3.xlsx', sheet_name='resource')\n",
    "wb = openpyxl.load_workbook('L3.xlsx')\n",
    "\n",
    "\n",
    "class ThemeColorConverter:\n",
    "    RGBMAX = 0xff\n",
    "    HLSMAX = 240\n",
    "\n",
    "    def __init__(self, wb):\n",
    "        self.colors = self.get_theme_colors(wb)\n",
    "\n",
    "    @staticmethod\n",
    "    def tint_luminance(tint, lum):\n",
    "        if tint < 0:\n",
    "            return int(round(lum * (1.0 + tint)))\n",
    "        return int(round((ThemeColorConverter.HLSMAX - lum) * tint)) + lum\n",
    "\n",
    "    @staticmethod\n",
    "    def ms_hls_to_rgb(hue, lightness=None, saturation=None):\n",
    "        if lightness is None:\n",
    "            hue, lightness, saturation = hue\n",
    "        hlsmax = ThemeColorConverter.HLSMAX\n",
    "        return hls_to_rgb(hue / hlsmax, lightness / hlsmax, saturation / hlsmax)\n",
    "\n",
    "    @staticmethod\n",
    "    def rgb_to_hex(red, green=None, blue=None):\n",
    "        if green is None:\n",
    "            red, green, blue = red\n",
    "        return '{:02X}{:02X}{:02X}'.format(\n",
    "            int(red * ThemeColorConverter.RGBMAX),\n",
    "            int(green * ThemeColorConverter.RGBMAX),\n",
    "            int(blue * ThemeColorConverter.RGBMAX)\n",
    "        )\n",
    "\n",
    "    @staticmethod\n",
    "    def rgb_to_ms_hls(red, green=None, blue=None):\n",
    "        if green is None:\n",
    "            if isinstance(red, str):\n",
    "                if len(red) > 6:\n",
    "                    red = red[-6:]  # Ignore preceding '#' and alpha values\n",
    "                rgbmax = ThemeColorConverter.RGBMAX\n",
    "                blue = int(red[4:], 16) / rgbmax\n",
    "                green = int(red[2:4], 16) / rgbmax\n",
    "                red = int(red[0:2], 16) / rgbmax\n",
    "            else:\n",
    "                red, green, blue = red\n",
    "        h, l, s = rgb_to_hls(red, green, blue)\n",
    "        hlsmax = ThemeColorConverter.HLSMAX\n",
    "        return (int(round(h * hlsmax)), int(round(l * hlsmax)),\n",
    "                int(round(s * hlsmax)))\n",
    "\n",
    "    @staticmethod\n",
    "    def get_theme_colors(wb):\n",
    "        from openpyxl.xml.functions import QName, fromstring\n",
    "        xlmns = 'http://schemas.openxmlformats.org/drawingml/2006/main'\n",
    "        root = fromstring(wb.loaded_theme)\n",
    "        themeEl = root.find(QName(xlmns, 'themeElements').text)\n",
    "        colorSchemes = themeEl.findall(QName(xlmns, 'clrScheme').text)\n",
    "        firstColorScheme = colorSchemes[0]\n",
    "        colors = []\n",
    "        for c in ['lt1', 'dk1', 'lt2', 'dk2', 'accent1', 'accent2', 'accent3', 'accent4', 'accent5', 'accent6']:\n",
    "            accent = firstColorScheme.find(QName(xlmns, c).text)\n",
    "            for i in list(accent):\n",
    "                if 'window' in i.attrib['val']:\n",
    "                    colors.append(i.attrib['lastClr'])\n",
    "                else:\n",
    "                    colors.append(i.attrib['val'])\n",
    "        return colors\n",
    "\n",
    "    def theme_and_tint_to_rgb(self, theme, tint):\n",
    "        rgb = self.colors[theme]\n",
    "        h, l, s = self.rgb_to_ms_hls(rgb)\n",
    "        return self.rgb_to_hex(self.ms_hls_to_rgb(h, self.tint_luminance(tint, l), s))\n",
    "\n",
    "\n",
    "def get_cell_color(cell):\n",
    "    theme_color = ThemeColorConverter(wb) # 获取基础色调\n",
    "    color = cell.fill.start_color\n",
    "    if color.type == \"rgb\":\n",
    "        return color.rgb\n",
    "    elif color.type == \"indexed\":\n",
    "        color_index = color.indexed\n",
    "        if color_index is None or color_index < len(COLOR_INDEX):\n",
    "            raise Exception(\"Invalid indexed color\")\n",
    "        return COLOR_INDEX[color_index]\n",
    "    elif color.type == \"theme\":\n",
    "        return \"FF\" + theme_color.theme_and_tint_to_rgb(color.theme, color.tint)\n",
    "    else:\n",
    "        raise Exception(f\"Other type: {color.type}\")\n",
    "\n",
    "\n",
    "def check_resource(color):\n",
    "    if color == copper_color:\n",
    "        return 'Copper'\n",
    "    elif color == tin_color:\n",
    "        return 'Tin'\n",
    "    elif color == icon_color:\n",
    "        return 'Iron'\n",
    "    elif color == mithril_color:\n",
    "        return 'Mithril'\n",
    "    elif color == thorium_color:\n",
    "        return 'Thorium'\n",
    "\n",
    "\n",
    "copper_color = get_cell_color(wb['resource']['B1'])\n",
    "tin_color = get_cell_color(wb['resource']['C1'])\n",
    "icon_color = get_cell_color(wb['resource']['D1'])\n",
    "mithril_color = get_cell_color(wb['resource']['E1'])\n",
    "thorium_color = get_cell_color(wb['resource']['F1'])\n",
    "schedule = wb['mining schedule']\n",
    "\n",
    "print('请输入player_id：') # 基于表格的位置读取日期的\n",
    "player_id = int(input())\n",
    "print('请输入种族：')\n",
    "race = input()\n",
    "print('请输入初始xp：')\n",
    "xp = int(input())\n",
    "print('请输入初始金币：')\n",
    "gold_collected = float(input())\n",
    "print('请输入当前位置：') # L2的当前位置\n",
    "current_location = input()\n",
    "player_xp, sliver_collected = get_money(race, xp, gold_collected, current_location)\n",
    "\n",
    "\n",
    "resource_remain = {\n",
    "    'Copper': 0, \n",
    "    'Tin': 0, \n",
    "    'Iron': 0, \n",
    "    'Mithril': 0, \n",
    "    'Thorium': 0, \n",
    "    'gold_collected': sliver_collected/100,\n",
    "    'week': '1'\n",
    "}\n",
    "\n",
    "\n",
    "while True:\n",
    "    # week 1\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 2)))\n",
    "    start_date = schedule.cell(player_id+1, 1).value\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '1'\n",
    "    \n",
    "    stack = schedule.cell(player_id+1, 2).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 2).value % 20 + resource_remain[resource_type]\n",
    "\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "    \n",
    "    # week 2\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 3)))\n",
    "    start_date = start_date + datetime.timedelta(days=7)\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '2'\n",
    "    stack = schedule.cell(player_id+1, 3).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 3).value % 20 + resource_remain[resource_type]\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "\n",
    "    \n",
    "    # week 3\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 4)))\n",
    "    start_date = start_date + datetime.timedelta(days=7)\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '3'\n",
    "    stack = schedule.cell(player_id+1, 4).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 4).value % 20 + resource_remain[resource_type]\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "\n",
    "    \n",
    "    # week 4\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 5)))\n",
    "    start_date = start_date + datetime.timedelta(days=7)\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '4'\n",
    "    stack = schedule.cell(player_id+1, 5).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 5).value % 20 + resource_remain[resource_type]\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "    \n",
    "    # week 5\n",
    "    resource_type = check_resource(get_cell_color(schedule.cell(player_id+1, 6)))\n",
    "    start_date = start_date + datetime.timedelta(days=7)\n",
    "    sell_date = start_date + datetime.timedelta(days=6)\n",
    "    resource_remain['week'] = '5'\n",
    "    stack = schedule.cell(player_id+1, 6).value // 20\n",
    "    resource_remain[resource_type] = schedule.cell(player_id+1, 6).value % 20 + resource_remain[resource_type]\n",
    "    resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][resource_type] * stack).values[0] + resource_remain['gold_collected']\n",
    "    for i in ['Copper', 'Tin', 'Iron', 'Mithril', 'Thorium']:\n",
    "        if resource_remain[i] >= 20:\n",
    "            stack = resource_remain[i] // 20\n",
    "            resource_remain[i] = resource_remain[i] % 20\n",
    "            resource_remain['gold_collected'] = (resource[resource['date'] == sell_date][i]*stack).values[0] + resource_remain['gold_collected']\n",
    "    if resource_remain['gold_collected'] >= 90:\n",
    "        break\n",
    "    \n",
    "\n",
    "print((resource_remain['gold_collected'] - 90) * 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1a412a1-fe19-4016-ba48-0a90a3c02d7f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "d4fe323a-1dda-41e9-928a-89f463524211",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入种族：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Tauren\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入初始xp：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 9500\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入初始金币：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 25.47\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入当前位置：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Mulgore\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入玩家职业：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Druid\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入L3后剩余银币：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 1684\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16.84\n",
      "玩家的总经验值： 348194\n",
      "玩家的总金币数： 20.64\n",
      "玩家的属性值： 79\n"
     ]
    }
   ],
   "source": [
    "# L4\n",
    "\n",
    "quest_list = pd.read_excel('L4.xlsx', sheet_name='Quest List')\n",
    "quest_item = pd.read_excel('L4.xlsx', sheet_name='Quest Item')\n",
    "class_stat = pd.read_excel('L4.xlsx', sheet_name='Stat')\n",
    "data = pd.merge(quest_list, quest_item, left_on='Item Granted', right_on='Item Name', how='left')\n",
    "\n",
    "print('请输入种族：')\n",
    "race = input()\n",
    "print('请输入初始xp：')\n",
    "xp = int(input())\n",
    "print('请输入初始金币：') # L2\n",
    "gold_collected = float(input())\n",
    "print('请输入当前位置：') # L2的当前位置\n",
    "current_location = input()\n",
    "player_xp, sliver_granted = get_money(race, xp, gold_collected, current_location) # 由Level2计算的xp\n",
    "print('请输入玩家职业：')\n",
    "player_class = input()\n",
    "\n",
    "\n",
    "print('请输入L3后剩余银币：')\n",
    "sliver_granted = int(input())\n",
    "gold_granted = sliver_granted / 100\n",
    "print(gold_granted)\n",
    "target = class_stat[class_stat['Class'] == player_class]['Target'].values[0]\n",
    "\n",
    "if player_class in ['Warlock', 'Priest', 'Mage']:\n",
    "    player_class = 'Warlock, Priest, Mage'\n",
    "elif player_class in ['Druid', 'Rogue']:\n",
    "    player_class = 'Druid, Rogue'\n",
    "\n",
    "\n",
    "class_data = data[data['Available to Class'] == player_class]\n",
    "class_data.sort_values(by=['Amount of Stats', 'XP Granted'], ascending=False, inplace=True)\n",
    "\n",
    "class_data['total_stat'] = class_data['Amount of Stats'].cumsum()\n",
    "class_data['xp_granted'] = class_data['XP Granted'].cumsum()\n",
    "class_data['gold_granted'] = class_data['Gold Granted'].cumsum()\n",
    "player_xp = class_data[class_data['total_stat'] >= target]['xp_granted'].values[0] + player_xp\n",
    "gold_granted = class_data[class_data['total_stat'] >= target]['gold_granted'].values[0] + gold_granted\n",
    "stats_amount = class_data[class_data['total_stat'] >= target]['total_stat'].values[0]\n",
    "\n",
    "print('玩家的总经验值：', player_xp)\n",
    "print('玩家的总金币数：', gold_granted)\n",
    "print('玩家的属性值：', stats_amount)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e8d7f6ae-2350-4c76-ae74-d59277a598fa",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f3a4537-b88e-4241-8e8a-55c8f8fd084b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "95c5d868-08e5-4b18-91e6-5303bd1bd0b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入玩家职业：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Warlock\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入L4后的xp：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 335672\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入L4后的金币数：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 36.47\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入L4后的属性值：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 85\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "25247.0 200\n"
     ]
    }
   ],
   "source": [
    "## L5\n",
    "dungeons = pd.read_excel('L5.xlsx')\n",
    "print('请输入玩家职业：')\n",
    "player_class = input()\n",
    "print('请输入L4后的xp：')\n",
    "player_xp = int(input())\n",
    "player_degree = degree[degree['total_xp'] <= player_xp]['degree'].max()\n",
    "\n",
    "visit_on_degree = 1\n",
    "armor_stats = 0\n",
    "armor_price = 0\n",
    "armor = 'null'\n",
    "print('请输入L4后的金币数：')\n",
    "gold_granted = float(input())\n",
    "print('请输入L4后的属性值：')\n",
    "stats_amount = int(input())\n",
    "\n",
    "if player_class == 'Mage':\n",
    "    player_class = 'Warlock, Mage'\n",
    "\n",
    "while True:\n",
    "    df = dungeons[dungeons['Min Level'] <= player_degree]\n",
    "    df.sort_values(['XP Granted', 'Min Level'], ascending=[False, False], inplace=True)\n",
    "\n",
    "    # 判断进入地下城次数\n",
    "    if visit_on_degree % 3 == 1:\n",
    "        data = df[df['Visit'] == '1, 4, 7,…']\n",
    "    elif visit_on_degree % 3 == 2:\n",
    "        data = df[df['Visit'] == '2, 5, 8,…']\n",
    "    else:\n",
    "        data = df[df['Visit'] == '3, 6, 9,…'] \n",
    "    \n",
    "    \n",
    "    if player_class != data['Class'].values[0]:\n",
    "        # Warlock单独判断\n",
    "        if player_class == 'Warlock':\n",
    "            if data['Class'].values[0] == 'Warlock, Mage':\n",
    "                if armor_stats <= data['Stats Amount'].values[0]: # 丢弃旧装备\n",
    "                    gold_granted = gold_granted + data['Gold Granted'].values[0] + armor_price\n",
    "                    armor_price = data['Sales Price'].values[0]\n",
    "                    stats_amount = stats_amount + data['Stats Amount'].values[0] - armor_stats\n",
    "                    armor_stats = data['Stats Amount'].values[0]\n",
    "                    armor = data['Gear Reward (Weapons)'].values[0]\n",
    "                else: # 丢弃新装备\n",
    "                    gold_granted += data['Gold Granted'].values[0]\n",
    "            else:\n",
    "                gold_granted = gold_granted + data['Gold Granted'].values[0] + data['Sales Price'].values[0]\n",
    "        else:\n",
    "            gold_granted = gold_granted + data['Gold Granted'].values[0] + data['Sales Price'].values[0]\n",
    "    else:\n",
    "        # 判断新获得的装备是否比旧装备强，强则丢弃旧装备，反之丢弃新装备\n",
    "        if armor_stats <= data['Stats Amount'].values[0]: # 丢弃旧装备\n",
    "            gold_granted = gold_granted + data['Gold Granted'].values[0] + armor_price\n",
    "            armor_price = data['Sales Price'].values[0]\n",
    "            stats_amount = stats_amount + data['Stats Amount'].values[0] - armor_stats\n",
    "            armor_stats = data['Stats Amount'].values[0]\n",
    "            armor = data['Gear Reward (Weapons)'].values[0]\n",
    "        else: # 丢弃新装备\n",
    "            gold_granted = gold_granted + data['Gold Granted'].values[0] + data['Sales Price'].values[0]\n",
    "            \n",
    "\n",
    "    # 判断等级\n",
    "    player_xp += data['XP Granted'].values[0]\n",
    "    player_degree = degree[degree['total_xp'] <= player_xp]['degree'].max()\n",
    "    # print(player_xp, player_degree, gold_granted, stats_amount, armor_stats)\n",
    "    if player_degree == 60:\n",
    "        break\n",
    "    else:\n",
    "        # 查看是否能否开启下一级地下城\n",
    "        if df.shape[0] < dungeons[dungeons['Min Level'] <= player_degree].shape[0]: # 能够开启下一个地下城\n",
    "            visit_on_degree = 1 # 探索次数重置为1\n",
    "        else:\n",
    "            visit_on_degree += 1 \n",
    "            \n",
    "print(gold_granted*100, stats_amount)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4679b257-e7a9-4e05-b110-5733d161fdd6",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "30b02317-8ec0-4f71-98ee-27f0dd1cd019",
   "metadata": {},
   "outputs": [],
   "source": [
    "# L6\n",
    "attribute_df = pd.read_excel('L6.xlsx', sheet_name='attribute')\n",
    "opponent_df = pd.read_excel('L6.xlsx', sheet_name='opponent')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b67545a9-dd29-4d70-96ea-0f09f34356b9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "id": "3cbcdccf-6402-435b-b675-2181417820cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入玩家a的职业：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Shaman\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入玩家b的职业：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " Warrior\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入玩家A的属性值：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 195\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入玩家B的属性值：\n"
     ]
    },
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      " 476\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "35\n"
     ]
    }
   ],
   "source": [
    "print('请输入玩家a的职业：')\n",
    "player_class_a = input()\n",
    "A = attribute_df[attribute_df['Class'] == player_class_a].to_dict('records')[0]\n",
    "print('请输入玩家b的职业：')\n",
    "player_class_b = input()\n",
    "B = attribute_df[attribute_df['Class'] == player_class_b].to_dict('records')[0]\n",
    "\n",
    "hp_a = (60 * 50) * A['HP %']\n",
    "hp_b = (60 * 50) * B['HP %']\n",
    "seconds = 0\n",
    "print('请输入玩家A的属性值：')\n",
    "player_attribute_a = int(input())\n",
    "print('请输入玩家B的属性值：')\n",
    "player_attribute_b = int(input())\n",
    "if A['Combat Stat'] == 'DPS':\n",
    "    damage_a = player_attribute_a * A['Combat Multiplier']\n",
    "    healer_a = 0\n",
    "else: \n",
    "    damage_a = 0\n",
    "    healer_a = player_attribute_a * A['Combat Multiplier']\n",
    "if B['Combat Stat'] == 'DPS':\n",
    "    damage_b = player_attribute_b * B['Combat Multiplier']\n",
    "    healer_b = 0\n",
    "else: \n",
    "    damage_b = 0\n",
    "    healer_b = player_attribute_b * B['Combat Multiplier']\n",
    "\n",
    "while (hp_a > 0) & (hp_b > 0):\n",
    "    hp_a -= damage_b\n",
    "    hp_a += healer_a\n",
    "    hp_b -= damage_a\n",
    "    hp_b += healer_b\n",
    "    seconds += 1\n",
    "\n",
    "print(seconds)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93dcfe1a-39a4-4c17-9d12-0a5b7d5e8ad4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fbe0327d-b4ee-45a1-a2e2-113d9965abc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# L7\n",
    "boss_df = pd.read_excel('L7.xlsx', sheet_name='boss')\n",
    "ally_df = pd.read_excel('L7.xlsx', sheet_name='ally')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "540c131f-3a9e-4f7a-a857-982c64c05ba6",
   "metadata": {},
   "outputs": [],
   "source": [
    "boss = 'Magmadar'\n",
    "boss_attr = boss_df[boss_df['Boss'] == boss].to_dict('records')[0]\n",
    "# ally = [1, 9, 10, 8, 5]\n",
    "# player_combat = pd.DataFrame({\n",
    "#     'DPS': [476, '', '', '', ''],\n",
    "#     'HPS': [0, ],\n",
    "#     'HP': [3000*1.15]\n",
    "# }, index=ally)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "90a3ee10-5120-44f6-a6b2-4f69fee1467c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Class</th>\n",
       "      <th>DPS</th>\n",
       "      <th>HPS</th>\n",
       "      <th>HP</th>\n",
       "      <th>AttackedOrder</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Warrior</td>\n",
       "      <td>476.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3450.0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Warrior</td>\n",
       "      <td>476.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3450.0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Warlock</td>\n",
       "      <td>500.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2400.0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Warlock</td>\n",
       "      <td>500.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2400.0</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Priest</td>\n",
       "      <td>0.0</td>\n",
       "      <td>304.5</td>\n",
       "      <td>2400.0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Class    DPS    HPS      HP  AttackedOrder\n",
       "0  Warrior  476.0    0.0  3450.0              1\n",
       "1  Warrior  476.0    0.0  3450.0              2\n",
       "2  Warlock  500.0    0.0  2400.0              3\n",
       "3  Warlock  500.0    0.0  2400.0              4\n",
       "4   Priest    0.0  304.5  2400.0              5"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 依次输入五个玩家（abcde）的属性\n",
    "def player_info(player_class, stat, attacked_order):\n",
    "    attr = attribute_df[attribute_df['Class'] == player_class].to_dict('records')[0]\n",
    "    if attr['Combat Stat'] == 'DPS':\n",
    "        damage = stat * attr['Combat Multiplier']\n",
    "        healer = 0\n",
    "    else: \n",
    "        damage = 0\n",
    "        healer = stat * attr['Combat Multiplier']\n",
    "    return {\n",
    "        'Class': player_class,\n",
    "        'DPS': damage,\n",
    "        'HPS': healer,\n",
    "        'HP': (60*50)*attr['HP %'],\n",
    "        'AttackedOrder': attacked_order\n",
    "    }\n",
    "\n",
    "player_a = player_info('Warrior', 476, 1) # 玩家1\n",
    "player_b = player_info('Warrior', 476, 2) # 玩家4\n",
    "player_c = player_info('Warlock', 200, 3) # David\n",
    "player_d = player_info('Warlock', 200, 4) # 玩家3\n",
    "player_e = player_info('Priest', 203, 5) # 玩家2\n",
    "combat_df = pd.DataFrame([player_a, player_b, player_c, player_d, player_e])\n",
    "combat_df\n",
    "\n",
    "boss_hp = boss_attr['HP']\n",
    "while boss_hp >= 0:\n",
    "    total_dps = \n",
    "    boss_hp -= total_dps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "id": "182d5055-5547-4109-9298-9a1a6481b0af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Boss': 'Magmadar',\n",
       " 'HP': 50000,\n",
       " 'DPS': 1250,\n",
       " 'XP Granted': 550000,\n",
       " 'Gold Granted': 2500}"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "boss_attr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36661dec-c24a-4446-a27c-851afa2cbcdb",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5982294-fa35-46e1-91d4-71638bc12832",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "595ea39f-aad9-4745-9171-a4cc878ba8d4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88f6afcc-268d-47d6-9818-fb7e5eccc851",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "anaconda-2024.02-py310",
   "language": "python",
   "name": "conda-env-anaconda-2024.02-py310-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
